package com.spring.lesson001.demo7;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author vhans
 */
public class DependOnTest {

    @Test
    public void normalBean() {
        System.out.println("容器启动中！");
        // 创建顺序与定义的顺序一样
        String beanXml = "dependOnByNo0017.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        System.out.println("容器启动完毕，准备关闭spring容器！");
        // 销毁的顺序与定义顺序相反
        context.close();
        System.out.println("spring容器已经关闭！");
    }

    @Test
    public void StrongDependOnBean() {
        System.out.println("容器启动中！");
        // 创建顺序与bean依赖的顺序一致
        String beanXml = "dependOnByStrong0017.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        System.out.println("容器启动完毕，准备关闭spring容器！");
        // 销毁的顺序与创建的顺序相反
        context.close();
        System.out.println("spring容器已经关闭！");
    }

    @Test
    public void YesDependOnBean() {
        System.out.println("容器启动中！");
        String beanXml = "dependOnByYes0017.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        System.out.println("容器启动完毕，准备关闭spring容器！");
        context.close();
        System.out.println("spring容器已经关闭！");
    }
}
